<?php
namespace common\components;


trait Errors
{
    private $errors;

    public function setError($key, $value)
    {
        $this->errors[$key] = $value;
    }

    public function getErrors()
    {
        return $this->errors;
    }

    public function getFirstError($key = null)
    {
        if ( $key ) {
            return isset($this->errors[$key]) ? $this->errors[$key] : null;
        }

        return $this->errors ? reset($this->errors) : null;
    }
}